Path: blob/master/Part 2 - Regression/Simple Linear Regression/[Python] Simple Linear Regression.ipynb
1009 views
Kernel: Python 3
Simple Linear Regression
In [10]:
In [13]:
Out[13]:
b0 is constant representing the base salary of anyone who come to profession and have no experience i.e. Experience = 0
b1 is coefficient representing the slope. The more experience the more raise will be their in salary.
Here in the graph, the black line is Best Fitting Line
In [17]:
Out[17]:
Actual value vs Model value and Ordinary Least Square
In [18]:
Out[18]:
Data Preprocessing
In [55]:
In [56]:
Out[56]:
array([[ 4. ],
[ 1.1],
[ 2.2],
[ 5.1],
[ 2.9],
[ 4.1],
[ 4. ],
[ 7.9],
[ 1.3],
[ 1.5],
[ 9. ],
[ 2. ],
[ 7.1],
[ 9.5],
[ 5.9],
[ 10.5],
[ 6.8],
[ 3.2],
[ 3.9],
[ 4.5],
[ 6. ],
[ 3. ]])
In [57]:
Out[57]:
array([[ 9.6],
[ 4.9],
[ 8.2],
[ 5.3],
[ 3.2],
[ 3.7],
[ 10.3],
[ 8.7]])
In [58]:
Out[58]:
array([ 56957., 39343., 39891., 66029., 56642., 57081.,
55794., 101302., 46205., 37731., 105582., 43525.,
98273., 116969., 81363., 121872., 91738., 54445.,
63218., 61111., 93940., 60150.])
In [59]:
Out[59]:
array([ 112635., 67938., 113812., 83088., 64445., 57189.,
122391., 109431.])
Fitting Simple Linear Regression to the Training Set
In [60]:
In [61]:
Out[61]:
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)
Predicting the Test set result
In [62]:
In [63]:
Out[63]:
array([ 115439.88180109, 71396.10622651, 102320.45928951,
75144.51265839, 55465.37889103, 60150.88693088,
121999.59305688, 107005.96732936])
Visualising the Training set results
X = Years of Experience
Y = Salary
In [68]:
Out[68]:
Text(0,0.5,'Salary')
Visualising the Test set results
In [70]:
Out[70]:
Text(0,0.5,'Salary')